package top.braycep.log;

import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtils {
    private static JTextPane tp;

    public static void setTextPane(JTextPane textPane) {
        tp = textPane;
    }

    public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void showLog(JTextPane textPane, String msg) {
        StringBuilder sb = new StringBuilder(textPane.getText());
        sb.append("\r\n");
        sb.append(dateFormat.format(new Date())).append("  ");
        sb.append(msg);
        sb.append("\r\n");
        textPane.setText(sb.toString());
    }

    public static void showLog(String msg) {
        StringBuilder sb = new StringBuilder(tp.getText());
        sb.append("\r\n");
        sb.append(dateFormat.format(new Date())).append("  ");
        sb.append(msg);
        sb.append("\r\n");
        tp.setText(sb.toString());
    }
}
